package controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import po.ComboboxItem;
import po.Cpu;
import po.Result;
import service.CpuService;

import java.util.List;

@Controller
@RequestMapping("/cpu")
public class CpuController {
    @Autowired
    private CpuService cpuService;

    @RequestMapping("/getCpuInfoView")
    public String getCpuInfoView() {
        return "resource/cpuInfo";
    }

    @RequestMapping("/findAllCpus")
    public @ResponseBody
    List<Cpu> findAllCpus(Cpu cpu) throws Exception {
        return cpuService.findAllCpus(cpu);
    }

    @RequestMapping("/getAddCpuView")
    public String getAddCpuView() {
        return "resource/addCpu";
    }

    @RequestMapping("/addCpu")
    public @ResponseBody
    Result addCpu(Cpu cpu) {
        return cpuService.addCpu(cpu);
    }

    @RequestMapping("/deleteCpuById")
    public @ResponseBody
    Result deleteCpuById(int id) {
        return cpuService.deleteCpuById(id);
    }

    @RequestMapping("/findCpuForComb")
    public @ResponseBody
    List<ComboboxItem> findCpuForComb() throws Exception {
        return cpuService.findCpuForComb();
    }

    @RequestMapping("/getEditCpuView")
    public String getEditCpuView() {
        return "resource/editCpu";
    }

    @RequestMapping("/updateCpu")
    public @ResponseBody
    Result updateCpu(Cpu cpu) {
        return cpuService.updateCpuById(cpu.getId(), cpu);
    }
}
